//
//  main.cpp
//  AirLogServer
//
//  Created by Penghao on 14-1-8.
//  Copyright (c) 2014年 PengHao.
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#include <iostream>
#include <time.h>
#include <vector>
#include "AirLog.h"
#include "AirMemPool.h"
#include "AirSocketServer.h"
#include "AirFreeBSDSocketServer.h"
#include "AirHttpServer.h"

int testHttpServer(){
    
    AirCpp::AirHttpServer *server = new AirCpp::AirHttpServer();
    if (server->init(8890, AF_INET, SOCK_STREAM, 0) < 0) {
    }else{
        server->start();
    }
    delete server;
    return 0;
}
//1128
long vector_test(){
    struct timeval start, end;
    gettimeofday( &start, NULL );
    vector<AirCpp::AirObject *> vec;
    for (int i = 0; i < 10000; ++i) {
        std::vector<AirCpp::AirObject *>::iterator it;
        it = vec.end();
        AirCpp::AirObject *obj = new AirCpp::AirObject();
        vec.insert(it, AirCpp::retain(obj));
        AirCpp::release(obj);
    }
    gettimeofday( &end, NULL );
    return 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec -start.tv_usec;
}

//212575

//1404
long array_test(){
    struct timeval start, end;
    gettimeofday( &start, NULL );
    
    AirCpp::AirMutableArray<AirCpp::AirObject> array;
    for (int i = 0; i < 10000; ++i) {
        AirCpp::AirObject *obj = new AirCpp::AirObject();
//        array.insert_object(obj, 0);
        array.add_object(obj);
        AirCpp::release(obj);
    }
    gettimeofday( &end, NULL );
    return 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec -start.tv_usec;
    
}

int main(int argc, const char * argv[])
{
    // insert code here...
    long times = 0;
    for (int i = 0; i < 3; ++i) {
        times+=array_test();
    }
    
    printf("time: %ld us\n", times/3);
    
    return 0;
    
    
    
    
    
    
    
    
    int port = 8890;
    if (argc == 2) {
        port = atoi(argv[1]);
        printf("port = %d \n", port);
    }
    
    AirCpp::AirFreeBSDSocketServer *server = new AirCpp::AirFreeBSDSocketServer();
    if (server->init(8890, AF_INET, SOCK_STREAM, 0) < 0) {
    }else{
        server->start();
    }
    delete server;
    return 0;
};